#include <iostream>
using namespace std;
#include <stack>

//stack栈的容器 先进后出 是简单的使用了deque来做的
//栈的算法 和 栈容器数据类型的分离的
void test1()
{
        stack<int> s;

        //入栈 push
        for (int i = 0; i < 10; i++)
        {
                s.push(i+1);
        }

        cout<<"栈的大小: "<<s.size()<<endl;
        
        //出栈 pop
        while (!s.empty())
        {
                int tmp = s.top(); //获取栈顶元素
                cout<<tmp<<" ";
                s.pop(); //弹出栈顶元素
        }
        cout<<endl;   
}

class Teacher
{
public:
        int age;
        char name[32];
public:
        void printT()
        {
                cout<<"age: "<<age <<endl;
        }
};

void test2()
{
        Teacher t1, t2, t3;
        t1.age = 31;
        t2.age = 32;
        t3.age = 33;

        stack<Teacher> s;
        s.push(t1);
        s.push(t2);
        s.push(t3);

        while (!s.empty())
        {
               Teacher tmp = s.top();
                tmp.printT();
                s.pop();
        }  
}

void test3()
{
        Teacher t1, t2, t3;
        t1.age = 31;
        t2.age = 32;
        t3.age = 33;

        stack<Teacher *> s;
        s.push(&t1);
        s.push(&t2);
        s.push(&t3);

        while (!s.empty())
        {
               Teacher *tmp = s.top();
                tmp->printT();
                s.pop();
        }  
}

int main(int argc, char const *argv[])
{
        // test1();        
        //test2();        
        test3();        
        return 0;
}
